package com.example.cinema.drawview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import java.lang.reflect.Type;

public class RollNotice extends View {
    public RollNotice(Context context) {
        this(context,null);
    }

    public RollNotice(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public RollNotice(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private Paint paint;
    private int fontsize = 18;


    private void init()
    {
        paint = new Paint();
        paint.setColor(Color.parseColor("#ffffff"));
        paint.setTextSize(fontsize);
        paint.setStyle(Paint.Style.FILL);
        paint.setAntiAlias(true);
        paint.setDither(true);


    }

    private int width;
    private int height;
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int w = widthMeasureSpec;
        int h = heightMeasureSpec;
        width = resolveSize(w,widthMeasureSpec);
        height= resolveSize(h,heightMeasureSpec);
        setMeasuredDimension(width,height);
    }

    private int y;
    private int textlen;
    private String text = "我是一个大傻子";
    @Override
    protected void onDraw(Canvas canvas) {
        textlen = text.length();
        y = height/2+fontsize/2;
        canvas.drawText(text,0,y,paint);
        this.animate().translationX(width+textlen*fontsize).setDuration(5000).start();
        super.onDraw(canvas);
    }
}
